/**
 * @ConfigParse.as
 * 
 * @author sodaChen mail:asframe@163.com
 * @version 1.0
 * <br>Copyright (C), 2010 asFrame.com
 * <br>This program is protected by copyright laws.
 * <br>Program Name:AStruts2
 * <br>Date:2012-4-9
 */
package com.asframe.astruts2.config
{
	import com.asframe.astruts2.beans.AstrutsBeans;
	import com.asframe.astruts2.beans.CmdBean;
	import com.asframe.astruts2.beans.LoadingBean;
	import com.asframe.astruts2.beans.ModuleBean;
	import com.asframe.astruts2.beans.NoticeFilterBean;
	import com.asframe.astruts2.beans.SystemBean;
	import com.asframe.config.ConfigManager;
	
	import flash.utils.Dictionary;
	
	/**
	 *
	 * @author sodaChen
	 * @Date:2012-4-9
	 */
	public class ConfigParse implements IConfigParse
	{
		public function ConfigParse()
		{
		}
		
		public function configParse(configXML:XML):AstrutsBeans
		{
			//先解析System
			var astrutsBean:AstrutsBeans = new AstrutsBeans();
			ConfigManager.xmlToObj(configXML.systems[0],astrutsBean.systems);
			xmlToObj(astrutsBean.vars,configXML.elements("vars").children(),Dictionary);
			xmlToObj(astrutsBean.properties,configXML.elements("properties").children(),Dictionary);
			//loading
			xmlToObj(astrutsBean.loadings,configXML.elements("loadings").children(),LoadingBean);
			xmlToObj(astrutsBean.noticeFilters,configXML.elements("noticeFilters").children(),NoticeFilterBean);
			xmlToObj(astrutsBean.cmds,configXML.elements("cmds").children(),CmdBean);
			xmlToObj(astrutsBean.modules,configXML.elements("modules").children(),ModuleBean);

			var parseView:ParseViewConfig = new ParseViewConfig();
			astrutsBean.viewSetup = parseView.parseViewConfig(configXML.systems.viewSetup[0],true);
			try
			{
				parseView.xmlToViewBeans(astrutsBean.views,configXML.views[0].view);
			} 
			catch(error:Error) 
			{
				
			}
//			astrutsBean.viewSetup = astrutsBean.systems.viewSetup;
			return astrutsBean;
		}
		
		public static function xmlToObj(ary:Array,xmlList:XMLList,clazz:Class):void
		{
			for each (var xml:XML in xmlList) 
			{
				var bean:* = new clazz();
				ary.push(bean);
				ConfigManager.xmlToObj(xml,bean);
			}
		}
	}
}
